package ie.lawlor.amvc;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * @author brendan
 */
public class ConnectionList extends ArrayList {

	public ConnectionList() {
		super();
	}

	public ConnectionList(List connections) {
		super(connections);
	}
	
	public void setConnections(List connections){
		for (ListIterator itr = connections.listIterator();
			itr.hasNext();){
			add(itr.next());
		}
	}
	
	/**
	 * Flattens list of lists, where the inner list is also a ConnectionList. Used
	 * with Spring to allow lists to be built up from parent to child.
	 */
	public boolean add(Object item){
		if (item instanceof ConnectionList){
			ConnectionList dataList = (ConnectionList)item;
			return super.addAll(dataList);
		} else{
			return super.add(item);
		}
	}
	
}
